//
//  DQBAppCon.h
//  DrivingQuestionBank
//
//  Created by mac on 2023/12/28.
//

#ifndef DQBAppCon_h
#define DQBAppCon_h

#define KEYWINDOW  [UIApplication sharedApplication].keyWindow

/** 屏幕宽高 */
#define ScreenBounds [UIScreen mainScreen].bounds
#define ScreenWidth [[UIScreen mainScreen]bounds].size.width
#define ScreenHeight [[UIScreen mainScreen]bounds].size.height

/**屏幕适配*/
#define Screen_width(a) (CGFloat)a * ScreenWidth / 375.0
#define Screen_height(a) (CGFloat)a * ScreenHeight / 667.0

/** 系统版本 */
#define DeviceSystemVersion [[UIDevice currentDevice] systemVersion]
#define iOS13_or_later [UIDevice currentDevice].systemVersion.floatValue >= 13.0

#define SafeBottomHeight (ScreenHeight >= 812.0 ? 83 : 49)
#define SafeAreaBottomHeight (ScreenHeight >= 812.0 ? 34 : 0)
#define SafeAreaTopHeight (ScreenHeight >= 812.0 ? 88 : 64)
#define SafeAreaNavigateHeight (ScreenHeight >= 812.0 ? 24 : 0)
#define SafeAreaHeight (SafeAreaBottomHeight+SafeAreaTopHeight)
#define NavigateHeight (ScreenHeight >= 812.0 ? 88 : 64)


#define PFR [[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 ? @"PingFangSC-Regular" : @"PingFang SC"


/**定义UIImage对象 */
#define IMAGE_NAMED(name)[UIImage imageNamed:name]

/**字体*/
#define BOLD_SYSTEMFONT(FONTSIZE)[UIFont boldSystemFontOfSize:FONTSIZE]//加粗

#define SYSTEM_FONT(FONTSIZE)[UIFont systemFontOfSize:FONTSIZE]

#define FONT(NAME,FONTSIZE)[UIFont fontWithName:(NAME)size:(FONTSIZE)]

//获取temp
#define kPathTemp NSTemporaryDirectory()
//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
//宏定义检测block是否可用
#define DTBLOCK_EXEC(block, ...) if (block) { block(__VA_ARGS__); };

/** 是否为空 */
#define checkNull(__X__)        (__X__) == (NSString *)[NSNull null] || (__X__) == nil ? @"" : [NSString stringWithFormat:@"%@", (__X__)]

//NSUserDefaults 实例化
#define kUserDefaults [NSUserDefaults standardUserDefaults]

//颜色
#define DQBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(1.0)]

#define DQBColorA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

#define DQBRGBHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]


//重写NSLog,Debug模式下打印日志和当前行数
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\n控制器:%s line: %d content :%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif

#define WEAK  @weakify(self);

#define STRONG  @strongify(self);


//弱引用：
#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif


//强引用：
#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif

#endif /* DQBAppCon_h */
